home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / Dylan Related / Mindy / Mindy 1.2 - portable sources / interp / parser.y < prev    next >
Encoding:
Text File  |  1995-03-15  |  3.1 KB  |  143 lines  |  [TEXT/ttxt]

  1. /**********************************************************************\
  2. *
  3. *  Copyright (c) 1994  Carnegie Mellon University
  4. *  All rights reserved.
  5. *  
  6. *  Use and copying of this software and preparation of derivative
  7. *  works based on this software are permitted, including commercial
  8. *  use, provided that the following conditions are observed:
  9. *  
  10. *  1. This copyright notice must be retained in full on any copies
  11. *     and on appropriate parts of any derivative works.
  12. *  2. Documentation (paper or online) accompanying any system that
  13. *     incorporates this software, or any part of it, must acknowledge
  14. *     the contribution of the Gwydion Project at Carnegie Mellon
  15. *     University.
  16. *  
  17. *  This software is made available "as is".  Neither the authors nor
  18. *  Carnegie Mellon University make any warranty about the software,
  19. *  its performance, or its conformity to any specification.
  20. *  
  21. *  Bug reports, questions, comments, and suggestions should be sent by
  22. *  E-mail to the Internet address "gwydion-bugs@cs.cmu.edu".
  23. *
  24. ***********************************************************************
  25. *
  26. * $Header: parser.y,v 1.8 94/10/05 21:04:23 nkramer Exp $
  27. *
  28. * This file is the parser for the debugger.
  29. *
  30. \**********************************************************************/
  31.  
  32. %{
  33. #include "../compat/std-c.h"
  34.  
  35. #include "mindy.h"
  36. #include "lexer.h"
  37. #include "parser.h"
  38. #include "list.h"
  39. #include "str.h"
  40. #include "sym.h"
  41. #include "num.h"
  42. #include "bool.h"
  43.  
  44.  
  45. static void yyerror(char *);
  46.  
  47. static obj_t result;
  48.  
  49. %}
  50.  
  51. %token tok_TRUE
  52. %token tok_FALSE
  53. %token tok_ERROR
  54. %token tok_LPAREN
  55. %token tok_RPAREN
  56. %token tok_DEBUGVAR
  57. %token tok_ARG
  58. %token tok_NUMBER
  59. %token tok_CHARACTER
  60. %token tok_STRING
  61. %token tok_ADDRESS
  62. %token tok_SYMBOL
  63. %token tok_KEYWORD
  64. %token tok_COMMA
  65.  
  66. %%
  67.  
  68. start:
  69.         command exprlist
  70.             { result = pair($1,$2); }
  71.     |    command
  72.             { result = pair($1,obj_Nil); }
  73.     |    /* epsilon */
  74.             { result = obj_Nil; }
  75.     |    error
  76.             { result = make_byte_string("command error: try ``help''"); }
  77. ;
  78.  
  79. command:    tok_SYMBOL
  80. ;
  81.  
  82. exprlist:    expr
  83.             { $$ = list1($1); }
  84.     |    expr tok_COMMA exprlist
  85.             { $$ = pair($1, $3); }
  86. ;
  87.  
  88. expr:        leaf
  89.             { $$ = $1; }
  90.     |    expr tok_LPAREN tok_RPAREN
  91.             { $$ = list2(symbol("funcall"), $1); }
  92.     |    expr tok_LPAREN arglist tok_RPAREN
  93.             { $$ = pair(symbol("funcall"), pair($1, $3)); }
  94. ;
  95.  
  96. leaf:        tok_DEBUGVAR
  97.             { $$ = pair(symbol("debug-var"), $1); }
  98.     |    tok_ARG
  99.             { $$ = pair(symbol("arg"), $1); }
  100.     |    tok_SYMBOL
  101.             { $$ = pair(symbol("variable"), $1); }
  102.     |    literal
  103.             { $$ = pair(symbol("literal"), $1); }
  104. ;
  105.  
  106. literal:    tok_TRUE
  107.             { $$ = obj_True; }
  108.     |    tok_FALSE
  109.             { $$ = obj_False; }
  110.     |    tok_KEYWORD
  111.     |    tok_STRING
  112.     |    tok_CHARACTER
  113.     |    tok_NUMBER
  114.     |    tok_ADDRESS
  115. ;
  116.  
  117. arglist:    expr more_args
  118.             { $$ = pair($1, $2); }
  119.     |    tok_KEYWORD expr more_args
  120.             { $$ = pair(pair(symbol("literal"),$1),pair($2, $3)); }
  121. ;
  122.  
  123. more_args:    /* epsilon */
  124.             { $$ = obj_Nil; }
  125.     |    tok_COMMA arglist
  126.             { $$ = $2; }
  127. ;
  128.  
  129. %%
  130.  
  131. static void yyerror(char *msg)
  132. {
  133.     yyinput_clear();
  134. }
  135.  
  136. YYSTYPE parse_command(FILE *input)
  137. {
  138.     extern int yyparse();
  139.     yyinput_setter(input);
  140.     return yyparse() ? obj_False : result;
  141. }
  142.  
  143.